/*
 * Copyright 2010 Mttang.com All right reserved. This software is the
 * confidential and proprietary information of Mttang.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Mttang.com.
 */
package com.mttang.sys.integration.dao.support;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapException;
import com.mttang.sys.dto.TreeDTO;
import com.mttang.sys.integration.dao.DepartmentDAO;

/**
 * 类MenuDAOImpl.java的实现描述：TODO 类实现描述 
 * @author acc 2010-6-1 上午11:16:08
 */
@SuppressWarnings("unchecked")
public class DepartmentDAOImpl extends SqlMapClientDaoSupport implements DepartmentDAO{

    private Log logger = LogFactory.getLog(getClass());
    /* (non-Javadoc)
     * @see com.mttang.sys.biz.service.MenuService#delete(com.mttang.sys.dto.MenuDTO)
     */
 
    @Override
    public void delDept(Map<Object, Object> paraMap) {

    	if (logger.isInfoEnabled()) {
            logger.info("---DepartmentDAOImpl.delDept()-- Begin----");
        }
		
		try{
			getSqlMapClientTemplate().delete("SYS.delDept", paraMap);
		}
		catch(SqlMapException ex){
			if (logger.isErrorEnabled()) {
	            logger.info("error:" + ex);
	        }
		}
		
    	if (logger.isInfoEnabled()) {
            logger.info("---DepartmentServiceImpl.delDept()-- End----");
        }

    }
    
    
    /**###########################################
     * 部门接口人指定 Add by ZhaoBin
     * #############################################
     */
    
    
    /**
     * 部门信息查询，包括领导人
     */
    @Override
    public Map getDepInfo(Map paraMap){
        if (logger.isInfoEnabled()) {logger.info("---部门信息dao--");}
        try{
            return (Map)this.getSqlMapClientTemplate().queryForObject("SYS.find-dep-info-by-userid",paraMap);
        }catch(SqlMapException e){
            if (logger.isInfoEnabled()) {logger.info("---部门信息异常dao--"+e);}
        }
        return null;
    }
    
    /**
     * 部门接口人查询
     */
    @Override
    public Map getDepLeaderByDepId(Map paraMap){
        if (logger.isInfoEnabled()) {logger.info("---部门接口人查询dao--");}
        try{
            return (Map)this.getSqlMapClientTemplate().queryForObject("SYS.find-dep-info-by-depid",paraMap);
        }catch(SqlMapException e){
            if (logger.isInfoEnabled()) {logger.info("---部门信息异常dao--"+e);}
        }
        return null;
    }
    
    
    /**
     * 部门查询
     */
    
    @Override
    public List<Map> queryDepAll(Map data){
        if (logger.isInfoEnabled()) {logger.info("---部门查询dao--");}
        try{
            return (List<Map>)this.getSqlMapClientTemplate().queryForList("SYS.findDepAll",data);
        }catch(SqlMapException e){
            if (logger.isInfoEnabled()) {logger.info("---部门查询异常dao--"+e);}
        }
        return null;
    }
    //接指接口人
    @Override
    public String addLeaderToDep(Map data){
        if (logger.isInfoEnabled()) {logger.info("---部门接口人指定dao--");}
        try{
            this.getSqlMapClientTemplate().insert("SYS.insertDepLeader", data);
            return "0";
        }catch(SqlMapException e){
            if (logger.isInfoEnabled()) {logger.info("---部门接口人指定dao异常--");}
            return "003";
        }
    }
    //修改接口人
    @Override
    public String updateLeaderToDep(Map data){
        if (logger.isInfoEnabled()) {logger.info("---修改接口人dao--");}
        try{
            this.getSqlMapClientTemplate().update("SYS.updateDepLeader",data);
            return "0";
        }catch(SqlMapException e){
            if (logger.isInfoEnabled()) {logger.info("---修改接口人dao异常--");}
            return "003";
        }
    }
    
    /**============================================
     * END----------
     * ===========================================
     */
    
    /* (non-Javadoc)
     * @see com.mttang.sys.biz.service.MenuService#findById(java.lang.Integer)
     */
    @Override
    public List<TreeDTO> qryDept(Map<Object, Object> paraMap) {
		if (logger.isInfoEnabled()) {
            logger.info("---DepartmentServiceImpl.qryDept()--Begin--");
        }
		
		List<TreeDTO> returnList = new ArrayList<TreeDTO>();
		
		try{
			returnList = getSqlMapClientTemplate().queryForList("SYS.qryDept", paraMap);

			if (logger.isInfoEnabled()) {
	            logger.info("---DepartmentServiceImpl.qryDept()--End--");
	        }
		}
		catch(SqlMapException ex){
			if (logger.isErrorEnabled()) {
	            logger.info("error:" + ex);
	        }
		}

		return returnList;
	}
    
    @Override
    public TreeDTO qryDeptById(int deptId) {
        Map<Object, Object> parameter = new HashMap<Object, Object>();
        parameter.put("DEPTID", deptId);
        return (TreeDTO) super.getSqlMapClientTemplate().queryForObject("SYS.qryDept", parameter);
    }

    /* (non-Javadoc)
     * @see com.mttang.sys.biz.service.MenuService#insert(com.mttang.sys.dto.MenuDTO)
     */
    @Override
    public void addDept(Map<Object, Object> paraMap) {

    	if (logger.isInfoEnabled()) {
            logger.info("---DepartmentDAOImpl.addDept()-- Begin----");
        }
		
		try{
			getSqlMapClientTemplate().insert("SYS.addDept", paraMap);
		}
		catch(SqlMapException ex){
			if (logger.isErrorEnabled()) {
	            logger.info("error:" + ex);
	        }
		}
		
    	if (logger.isInfoEnabled()) {
            logger.info("---DepartmentServiceImpl.addDept()-- End----");
        }

    }

    /* (non-Javadoc)
     * @see com.mttang.sys.biz.service.MenuService#update(com.mttang.sys.dto.MenuDTO)
     */
    @Override
    public void mdfDept(Map<Object, Object> paraMap) {

    	if (logger.isInfoEnabled()) {
            logger.info("---DepartmentDAOImpl.mdfDept()-- Begin----");
        }
		
		try{
			getSqlMapClientTemplate().update("SYS.mdfDept", paraMap);
		}
		catch(SqlMapException ex){
			if (logger.isErrorEnabled()) {
	            logger.info("error:" + ex);
	        }
		}
		
    	if (logger.isInfoEnabled()) {
            logger.info("---DepartmentServiceImpl.mdfDept()-- End----");
        }

    }

}
